package com.base.api.cdr;

import com.base.api.pms.PmsPublicSqlQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wnhuang
 * @Package com.base.api.cdr
 * @date 2020-12-19 12:36
 */
@Component
public class PatientSqlQuery extends PmsPublicSqlQuery {

    @Override
    public Map<String, Object> beforReturn(Map<String, Object> map) {
        Map<String,Object> map1 = new HashMap<>();
        map1.put("PageHospitalList",map);
        return map1;
    }

    @Override
    public String splicSql(String sql, Map<String, Object> param){
        StringBuilder param1 = new StringBuilder();
        if(param != null){
            if(param.get("HospitalNo") != null && !StringUtils.isBlank((String) (param.get("HospitalNo")))){
                param1.append(" and A.HOSPITAL_AREA = '" + param.get("HospitalNo") + "'");
            }
            if(param.get("PatientID") != null && !StringUtils.isBlank((String) (param.get("PatientID")))){
                param1.append(" and A.Patient_ID = '" + param.get("PatientID") + "'");
            }
            if(param.get("PatientName") != null && !StringUtils.isBlank((String) (param.get("PatientName")))){
                param1.append(" and A.Patient_NAME = '" + param.get("PatientName") + "'");
            }
            if(param.get("IDCard") != null && !StringUtils.isBlank((String) (param.get("IDCard")))){
                param1.append(" and P.ID_NUMBER = '" + param.get("IDCard") + "'");
            }
            if(param.get("CurrentDeptName") != null && !StringUtils.isBlank((String) (param.get("CurrentDeptName")))){
                param1.append(" and B.Current_Dept_Name = '" + param.get("CurrentDeptName") + "'");
            }
        }
        return MessageFormat.format(sql.replace("'","''"), param1.toString());
    };
}
